﻿
@{
    ViewBag.Title = "首页";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div class="layui-container p0 mt10">
    <div class="layui-row layui-col-space10">
        <div class="layui-col-md8">
            <div class="layui-carousel bcolor" id="banner">
                <div carousel-item id="dot_banner"></div>

                <script id="dot_tmp_banner" type="text/x-dot-template">
                    {{ for(var idx in it) { if(it[idx].ID) { var elm = it[idx]; }}
                    <div>
                        <a href="{{= elm.SourceUrl }}">
                            <img src="@ViewBag.ManageUrl{{= elm.Img }}" alt="" onerror="imageError(event)">
                        </a>
                    </div>
                    {{ } } }}
                </script>
            </div>
        </div>
        <div class="layui-col-md4 layui-hide-xs">
            <div class="layui-tab layui-tab-brief bcolor mt0 mb0">
                <ul class="layui-tab-title">
                    <li class="layui-this">最新公告</li>
                </ul>
                <div class="layui-tab-content pb0">
                    <div class="layui-tab-item layui-show listp" id="dot_proclaim"></div>

                    <script id="dot_tmp_proclaim" type="text/x-dot-template">
                        {{? it.length }}
                        {{ for(var idx in it) { if(it[idx].ID) { var elm = it[idx]; }}
                        <a href="/article/info/{{= elm.ID }}@(ViewBag.Suffix)" class="{{= idx < 3 ? "hot" : "" }} ahover">
                            <p>
                                {{= elm.Title }}
                                <span>{{= new Date(elm.CreateTime).format('yyyy-MM-dd') }}</span>
                            </p>
                        </a>
                        {{ } } }}
                        {{?? }}
                        <a href="javascript:void(0)">{{= noDataTitle }}</a>
                        {{? }}
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="layui-container p0 mt10">
    <div class="row">
        <div class="layui-col-md12 p0 bcolor" id="dot_proclaim_new"></div>

        <script id="dot_tmp_proclaim_new" type="text/x-dot-template">
            {{ for(var idx in it) { if(it[idx].ID) { var elm = it[idx]; }}
            <a href="/article/info/{{= elm.ID }}@(ViewBag.Suffix)">
                <div class="top-new" id="dot_proclaim_new">
                    <div class="new-title">
                        <h3>【最新公告】</h3>
                        <span class="ahover">{{= elm.Title }}</span>
                    </div>
                    <div class="new-content">
                        {{= elm.Content }}...
                    </div>
                </div>
            </a>
            {{ } break; } }}
        </script>
    </div>
</div>

<div class="layui-container p0 mt15">
    <div class="layui-row layui-col-space10">
        <div class="layui-col-md8">
            <div class="article-list" id="dot_home_list"></div>

            <script id="dot_tmp_home_list" type="text/x-dot-template">
                {{? it.length }}
                {{ for(var idx in it) { if(it[idx].ID) { var elm = it[idx]; }}
                <div class="row p20p10 bcolor oa">
                    <div class="layui-col-md3">
                        <a href="/article/info/{{= elm.ID }}@(ViewBag.Suffix)">
                            <img src="{{= fileurl + elm.Img }}" alt="" style="width:100%;" onerror="imageError(event)">
                        </a>
                    </div>
                    <div class="layui-col-md9">
                        <div class="new-panle">
                            <a href="/article/info/{{= elm.ID }}@(ViewBag.Suffix)">
                                <div class="panle-title ahover">{{= elm.Title }}</div>
                            </a>
                            <div class="panle-lable">
                                <a href="/article/index/{{= elm.ClassifyID }}@(ViewBag.Suffix)">
                                    <span class="layui-badge layui-bg-blue">{{= elm.ClassifyName }}</span>
                                </a>
                            </div>
                            <div class="panle-info">
                                <span>
                                    <i class="layui-icon">&#xe637;</i> {{= elm.CreateTime }}
                                </span>
                                <a href="/Page/Index/{{= elm.Number }}@(ViewBag.Suffix)" class="href" style="font-size:12px;" target="_blank">
                                    <i class="layui-icon" style="font-size:13px;">&#xe612;</i> {{= elm.UserName }}
                                </a>
                                <span style="margin-left:10px;">
                                    <i class="layui-icon">&#xe60c;</i> {{= elm.Praise }}
                                </span>
                                <span>
                                    <i class="layui-icon">&#xe615;</i> {{= elm.ClickAmount }}
                                </span>
                            </div>
                            <div class="panle-content">
                                {{= elm.Content }}...
                            </div>
                        </div>
                    </div>
                </div>
                {{ } } }}
                {{?? }}
                <div class="row p20p10 bcolor oa">{{= noDataTitle }}</div>
                {{? }}
            </script>
        </div>
        <div class="layui-col-md4">
            <div class="row">
                <div class="layui-tab layui-tab-brief bcolor oa m0">
                    <ul class="layui-tab-title">
                        <li class="layui-this">知识分类</li>
                    </ul>
                    <div class="layui-tab-content">
                        <div class="layui-tab-item layui-show lh30" id="dot_classify"></div>

                        <script id="dot_tmp_classify" type="text/x-dot-template">
                            {{? it.length }}
                            {{ for(var idx in it) { if(it[idx].ID) { var elm = it[idx]; }}
                            <a href="/article/index/{{= elm.ID }}@(ViewBag.Suffix)"><span class="layui-badge layui-bg-blue">{{= elm.Name }}</span></a>
                            {{ } } }}
                            {{?? }}
                            <a href="javascript:void(0)">{{= noDataTitle }}</a>
                            {{? }}
                        </script>
                    </div>
                </div>
            </div>

            <div class="row layui-hide-xs">
                <div class="layui-tab layui-tab-brief bcolor oa">
                    <ul class="layui-tab-title">
                        <li class="layui-this">推荐文章</li>
                    </ul>
                    <div class="layui-tab-content pb0">
                        <div class="layui-tab-item layui-show" id="dot_hot_art"></div>

                        <script id="dot_tmp_hot_art" type="text/x-dot-template">
                            {{? it.length }}
                            {{ for(var idx in it) { if(it[idx].ID) { var elm = it[idx]; }}
                            <div class="row oa pbt10 bt">
                                <div class="layui-col-md3">
                                    <a href="/article/info/{{= elm.ID }}@(ViewBag.Suffix)">
                                        <img src="{{= fileurl + elm.Img }}" alt="" style="width:100%;" onerror="imageError(event)">
                                    </a>
                                </div>
                                <div class="layui-col-md9">
                                    <div class="new-panle">
                                        <a href="/article/info/{{= elm.ID }}@(ViewBag.Suffix)">
                                            <div class="ahover">{{= elm.Title }}</div>
                                        </a>
                                        <div class="panle-info">
                                            <span>
                                                <i class="layui-icon">&#xe60c;</i> {{= elm.Praise }}
                                            </span>
                                            <span>
                                                <i class="layui-icon">&#xe615;</i> {{= elm.ClickAmount }}
                                            </span>
                                        </div>
                                        <div class="panle-content">
                                            {{= elm.Content }}...
                                        </div>
                                    </div>
                                </div>
                            </div>
                            {{ } } }}
                            {{?? }}
                            <div class="row oa pbt10 bt">{{= noDataTitle }}</div>
                            {{? }}
                        </script>
                    </div>
                </div>
            </div>

            <div class="row layui-hide-xs">
                <div class="layui-tab layui-tab-brief bcolor oa">
                    <ul class="layui-tab-title">
                        <li class="layui-this">热门讨论</li>
                    </ul>
                    <div class="layui-tab-content pb0">
                        <div class="layui-tab-item layui-show listp" id="dot_discuss"></div>

                        <script id="dot_tmp_discuss" type="text/x-dot-template">
                            {{? it.length }}
                            {{ for(var idx in it) { if(it[idx].ID) { var elm = it[idx]; }}
                            <a href="/article/info/{{= elm.ID }}@(ViewBag.Suffix)" class="ahover">
                                <p>
                                    {{= elm.Title }}
                                </p>
                            </a>
                            {{ } } }}
                            {{?? }}
                            <a href="javascript:void(0)" class="ahover">{{= noDataTitle }}</a>
                            {{? }}
                        </script>
                    </div>
                </div>
            </div>

            @*<div class="row layui-hide-xs">
                    <div class="layui-col-md12 layui-tab-brief bcolor oa">
                        <div class="layui-col-md12 layui-tab-brief bcolor oa">
                            <ul class="layui-tab-title">
                                <li class="layui-this">站点统计</li>
                            </ul>
                            <div class="layui-tab-content oa">
                                <div class="row pb10">
                                    <div class="layui-col-md6 mb10">今日访问：12520</div>
                                    <div class="layui-col-md6 mb10">昨日访问：12520</div>
                                    <div class="layui-col-md6 mb10">历史访问：12520</div>
                                    <div class="layui-col-md6 mb10">分类总数：12520</div>
                                    <div class="layui-col-md6 mb10">文章总数：12520</div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>*@
        </div>
    </div>
</div>

<script>
    var carousel = layui.carousel, element = layui.element;
    var home = new Home();
    $(function () {
        home.getIndex();
        home.getClassify();
        home.getHotArt();
        home.getHotDiscuss();
    });

    function Home() {
        this.getIndex = function () {
            $.post('/home/GetHomeIndexResult', {}, function (result) {
                var dotTmp = doT.template($("#dot_tmp_home_list").text());
                $("#dot_home_list").html(dotTmp(result.data.newArticle));

                dotTmp = doT.template($("#dot_tmp_proclaim").text());
                $("#dot_proclaim").html(dotTmp(result.data.newProclaim));

                dotTmp = doT.template($("#dot_tmp_proclaim_new").text());
                $("#dot_proclaim_new").html(dotTmp(result.data.newProclaim));

                dotTmp = doT.template($("#dot_tmp_banner").text());
                $("#dot_banner").html(dotTmp(result.data.Banner));

                layui.carousel.render({
                    elem: '#banner'
                    , width: '100%'
                    , height: '215px'
                    , arrow: 'always'
                });
            });
        };
        this.getClassify = function () {
            $.post('/home/GetClassifyResult', {}, function (result) {
                var dotTmp = doT.template($("#dot_tmp_classify").text());
                $("#dot_classify").html(dotTmp(result.data));
            });
        };
        this.getHotArt = function () {
            $.post('/home/GetHotArticleResult', {}, function (result) {
                var dotTmp = doT.template($("#dot_tmp_hot_art").text());
                $("#dot_hot_art").html(dotTmp(result.data));
            });
        };
        this.getHotDiscuss = function () {
            $.post('/home/GetHotDiscussResult', {}, function (result) {
                var dotTmp = doT.template($("#dot_tmp_discuss").text());
                $("#dot_discuss").html(dotTmp(result.data));
            });
        };
    };

</script>